﻿//-----------------------------------------------------------------------
// <copyright file="ShowPrivateMessagesCommand.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 
namespace ChatBox.UI.Windows.Main
{
    using ChatBox.UI.Commands;
    using ChatBox.UI.Windows.PrivateMessages;

    /// <summary>
    /// Command to show the private messages window
    /// </summary>
    public class ShowPrivateMessagesCommand : GenericCommandBase<MainWindowViewModel>
    {
        /// <summary>
        /// Execute the shutdown command
        /// </summary>
        /// <param name="value">the command data</param>
        public override void ExecuteOnValue(MainWindowViewModel value)
        {
            // check that basic setup is in place in order to log in
            if (!value.CheckNameAndPassword("show private messages"))
            {
                return;
            }

            value.ChatEngine.StartPrivate();

            if (value.PrivateMessagesWindow == null)
            {
                PrivateMessagesWindow window = new PrivateMessagesWindow();
                value.PrivateMessagesWindow = window;

                PrivateMessagesViewModel viewModel = Locator.Resolve<PrivateMessagesViewModel>();
                viewModel.OperationCompletedCommand = value.OperationCompletedCommand;

                viewModel.Window = window;

                window.DataContext = viewModel;
                window.HideOnClose = true;
                window.InitializeViewModel(value.HyperlinkContext);
                viewModel.ReadSettings();
            }

            value.PrivateMessagesWindow.Show();
        }
    }
}
